package com.example.demo.mapper;

import com.example.demo.entity.Player;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    @Select("select * from User where username=#{username}")
    User getUserInfo(String username);

    @Select("select * from player_info where username=#{username}")
    Player getPlayerInfo(String username);

    @Insert("insert into User (username, password) values (#{username}, #{password})")
    void addUserInfo(String username, String password);

    @Insert("insert into player_info values (#{username}, 0, 0, 0.0, #{register_time})")
    void addPlayerInfo(String username, String register_time);

    @Insert("insert into finish_record values (#{username}, #{layout_id}, #{register_time})")
    void finishGame(String username, int layout_id, String register_time);

    @Update("update player_info set game_total_cnt=#{game_total_cnt}, game_finish_total_cnt=#{game_finish_total_cnt}, aver_finish_time=#{aver_finish_time} where username=#{username}")
    void updatePlayerInfo(String username, int game_total_cnt, int game_finish_total_cnt, float aver_finish_time);
}
